<template>
  <div>
    <el-tabs value="first">
      <el-tab-pane label="项目基本信息" name="first">
        <el-form size="small" :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="170px">
          <el-row>
            <el-col :span="12">
              <el-form-item label="项目编号" prop="projectCode">
                <el-input v-model="dataForm.projectCode" placeholder="项目编号"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="项目名称" prop="projectName">
                <el-input v-model="dataForm.projectName" placeholder="项目名称"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="行业类别" prop="tradeTypeName">
                <el-input v-model="dataForm.tradeTypeName" placeholder="行业类别名称"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="一级分类" prop="projectTypeOneName">
                <el-input v-model="dataForm.projectTypeOneName" placeholder="项目一级分类名称"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="二级分类" prop="projectTypeTwoName">
                <el-input v-model="dataForm.projectTypeTwoName" placeholder="项目二级分类名称"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="委托单" prop="entrustId">
                <el-input v-model="dataForm.entrustId" placeholder="委托单ID"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="合同" prop="contractId">
                <el-input v-model="dataForm.contractId" placeholder="合同ID"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="项目经理" prop="projectManager">
                <el-input v-model="dataForm.projectManager" placeholder="项目经理名称"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="服务对象" prop="feeServer">
                <el-input v-model="dataForm.feeServer" placeholder="服务对象用逗号隔开,,可选择两个个对象：招标人、中标人"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="招标代理" prop="feeMethod">
                <el-input v-model="dataForm.feeMethod" placeholder="招标代理服务费收取方式：有固定比例、差额定律累进制（输入80表示打八折）、固定金额、其他四种方式"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="项目板块" prop="projectBlock">
                <el-input v-model="dataForm.projectBlock" placeholder="项目板块：可选集团采购、蓝谷、信息化"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="监督部门" prop="supervision">
                <el-input v-model="dataForm.supervision" placeholder="监督部门"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="资金来源" prop="feeSource">
                <el-input v-model="dataForm.feeSource" placeholder="资金来源：财政资金、企业自筹、其他"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="项目概算" prop="budget">
                <el-input-number style="width: 100%" v-model="dataForm.budget" placeholder="项目概算, 标段预算/概算价之和"></el-input-number>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="年度计划" prop="scheduleName">
                <el-input v-model="dataForm.scheduleName" placeholder="年度计划"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="招标人" prop="tendereeName">
                <el-input v-model="dataForm.tendereeName" placeholder="招标人"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="招标内容与范围" prop="bidScope">
                <el-input v-model="dataForm.bidScope" placeholder="招标内容与范围"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="招标项目规模及概况" prop="bidContent">
                <el-input v-model="dataForm.bidContent" placeholder="招标项目规模及概况"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="省直辖市" prop="province">
                <el-input v-model="dataForm.province" placeholder="省直辖市"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="地市区县" prop="city">
                <el-input v-model="dataForm.city" placeholder="地市区县"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item label="备注" prop="remark">
                <el-input type="textarea" v-model="dataForm.remark" placeholder="备注"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
      </el-tab-pane>
    </el-tabs>

    <el-tabs value="first1">
      <el-tab-pane label="流程控制" name="first1">
        <el-form size="small" :model="dataForm" :rules="dataRule" ref="dataForm_flow" @keyup.enter.native="dataFormSubmit()" label-width="170px">
          <el-row>
            <el-col :span="12">
              <el-form-item label="需要购标" prop="needPurchase">
                <el-radio-group v-model="dataForm.needPurchase">
                  <el-radio :label="1">是</el-radio>
                  <el-radio :label="0">否</el-radio>
                </el-radio-group>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="招标方式" prop="bidMethod">
                <el-radio-group v-model="dataForm.bidMethod">
                  <el-radio :label="1">公开</el-radio>
                  <el-radio :label="0">邀请</el-radio>
                </el-radio-group>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="开标方式" prop="openMethod">
                <el-radio-group v-model="dataForm.openMethod">
                  <el-radio :label="1">网上</el-radio>
                  <el-radio :label="0">纸质、现场</el-radio>
                </el-radio-group>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="开标步制" prop="openStep">
                <el-radio-group v-model="dataForm.openStep">
                  <el-radio :label="1">是</el-radio>
                  <el-radio :label="0">否</el-radio>
                </el-radio-group>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="是否报名审核" prop="needApprove">
                <el-radio-group v-model="dataForm.needApprove">
                  <el-radio :label="1">是</el-radio>
                  <el-radio :label="0">否</el-radio>
                </el-radio-group>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="资格审查方式" prop="approveMethod">
                <el-radio-group v-model="dataForm.approveMethod">
                  <el-radio :label="1">预审</el-radio>
                  <el-radio :label="0">后审</el-radio>
                </el-radio-group>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="评标方式" prop="evaluateMethod">
                <el-radio-group v-model="dataForm.evaluateMethod">
                  <el-radio :label="1">网上</el-radio>
                  <el-radio :label="0">纸质、现场</el-radio>
                </el-radio-group>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="投标文件递交方式" prop="submitMethod">
                <el-radio-group v-model="dataForm.submitMethod">
                  <el-radio :label="1">一次递交</el-radio>
                  <el-radio :label="0">两次递交</el-radio>
                </el-radio-group>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
      </el-tab-pane>
    </el-tabs>

    <el-tabs value="first2">
      <el-tab-pane label="标段（包）信息" name="first2">
        <el-table
          size="mini"
          border
          style="width: 100%;">
          <el-table-column
            prop="Id"
            header-align="center"
            align="center"
            width="70px"
            label="序号">
          </el-table-column>
          <el-table-column
            prop="segmentCode"
            header-align="center"
            align="center"
            label="标段（包）名称">
          </el-table-column>
          <el-table-column
            prop="budget"
            header-align="center"
            align="center"
            label="预算/概算价">
          </el-table-column>
          <el-table-column
            fixed="right"
            header-align="center"
            align="center"
            width="120"
            label="操作">
            <template slot="header" slot-scope="scope">
              <el-button size="mini"  icon="el-icon-plus">添加标段</el-button>
            </template>
            <template slot-scope="scope">
              <el-button type="text" size="small">修改</el-button>
              <el-button type="text" size="small">删除</el-button>
            </template>
          </el-table-column>
        </el-table>
      </el-tab-pane>

      <el-tab-pane label="项目组成员" name="first3" style="margin-top: 20px">
        <el-table
          size="mini"
          border
          style="width: 100%;">
          <el-table-column
            prop="Id"
            header-align="center"
            align="center"
            width="70px"
            label="序号">
          </el-table-column>
          <el-table-column
            prop="segmentCode"
            header-align="center"
            align="center"
            label="姓名">
          </el-table-column>
          <el-table-column
            prop="budget"
            header-align="center"
            align="center"
            label="查看权限">
          </el-table-column>
          <el-table-column
            prop="budget"
            header-align="center"
            align="center"
            label="操作权限">
          </el-table-column>
          <el-table-column
            fixed="right"
            header-align="center"
            align="center"
            width="120"
            label="操作">
            <template slot="header" slot-scope="scope">
              <el-button size="mini"  icon="el-icon-plus">添加成员</el-button>
            </template>
            <template slot-scope="scope">
              <el-button type="text" size="small">修改</el-button>
              <el-button type="text" size="small">删除</el-button>
            </template>
          </el-table-column>
        </el-table>
      </el-tab-pane>
    </el-tabs>
    <div style="text-align: center; padding: 10px; margin-top: 10px">
      <el-button size="small" type="primary" @click="dataFormSubmit()">保存</el-button>
      <el-button size="small" type="primary" @click="dataFormSubmit()">生效</el-button>
      <el-button size="small" @click="$router.go(-1)">返回</el-button>
    </div>
  </div>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          id: 0,
          projectCode: '',
          projectName: '',
          tradeTypeId: '',
          tradeTypeName: '',
          projectTypeOneId: '',
          projectTypeOneName: '',
          projectTypeTwoId: '',
          projectTypeTwoName: '',
          entrustId: '',
          contractId: '',
          projectManagerId: '',
          projectManager: '',
          feeServer: '',
          feeMethod: '',
          projectBlock: '',
          supervision: '',
          feeSourceId: '',
          feeSource: '',
          needPurchase: '',
          budget: '',
          scheduleId: '',
          scheduleName: '',
          tendereeId: '',
          tendereeName: '',
          bidScope: '',
          bidContent: '',
          province: '',
          city: '',
          bidMethod: '',
          openMethod: '',
          openStep: '',
          needApprove: '',
          approveMethod: '',
          evaluateMethod: '',
          submitMethod: '',
          remark: '',
          createOn: '',
          createUserId: '',
          createBy: '',
          modifiedOn: '',
          modifiedUserId: '',
          modifiedBy: ''
        },
        dataRule: {
          projectCode: [
            { required: true, message: '项目编号不能为空', trigger: 'blur' }
          ],
          projectName: [
            { required: true, message: '项目名称不能为空', trigger: 'blur' }
          ],
          tradeTypeId: [
            { required: true, message: '行业类别ID不能为空', trigger: 'blur' }
          ],
          tradeTypeName: [
            { required: true, message: '行业类别名称不能为空', trigger: 'blur' }
          ],
          projectTypeOneId: [
            { required: true, message: '项目一级分类ID不能为空', trigger: 'blur' }
          ],
          projectTypeOneName: [
            { required: true, message: '项目一级分类名称不能为空', trigger: 'blur' }
          ],
          projectTypeTwoId: [
            { required: true, message: '项目二级分类ID不能为空', trigger: 'blur' }
          ],
          projectTypeTwoName: [
            { required: true, message: '项目二级分类名称不能为空', trigger: 'blur' }
          ],
          entrustId: [
            { required: true, message: '委托单ID不能为空', trigger: 'blur' }
          ],
          contractId: [
            { required: true, message: '合同ID不能为空', trigger: 'blur' }
          ],
          projectManagerId: [
            { required: true, message: '项目经理ID不能为空', trigger: 'blur' }
          ],
          projectManager: [
            { required: true, message: '项目经理名称不能为空', trigger: 'blur' }
          ],
          feeServer: [
            { required: true, message: '服务对象用逗号隔开,,可选择两个个对象：招标人、中标人不能为空', trigger: 'blur' }
          ],
          feeMethod: [
            { required: true, message: '招标代理服务费收取方式：有固定比例、差额定律累进制（输入80表示打八折）、固定金额、其他四种方式不能为空', trigger: 'blur' }
          ],
          projectBlock: [
            { required: true, message: '项目板块：可选集团采购、蓝谷、信息化不能为空', trigger: 'blur' }
          ],
          supervision: [
            { required: true, message: '监督部门不能为空', trigger: 'blur' }
          ],
          feeSourceId: [
            { required: true, message: '资金来源ID不能为空', trigger: 'blur' }
          ],
          feeSource: [
            { required: true, message: '资金来源：财政资金、企业自筹、其他不能为空', trigger: 'blur' }
          ],
          needPurchase: [
            { required: true, message: '是否需要购标,可选需要、不需要不能为空', trigger: 'blur' }
          ],
          budget: [
            { required: true, message: '项目概算, 标段预算/概算价之和不能为空', trigger: 'blur' }
          ],
          scheduleId: [
            { required: true, message: '年度计划ID不能为空', trigger: 'blur' }
          ],
          scheduleName: [
            { required: true, message: '年度计划不能为空', trigger: 'blur' }
          ],
          tendereeId: [
            { required: true, message: '招标人ID不能为空', trigger: 'blur' }
          ],
          tendereeName: [
            { required: true, message: '招标人不能为空', trigger: 'blur' }
          ],
          bidScope: [
            { required: true, message: '招标内容与范围不能为空', trigger: 'blur' }
          ],
          bidContent: [
            { required: true, message: '招标项目规模及概况不能为空', trigger: 'blur' }
          ],
          province: [
            { required: true, message: '省直辖市不能为空', trigger: 'blur' }
          ],
          city: [
            { required: true, message: '地市区县不能为空', trigger: 'blur' }
          ],
          bidMethod: [
            { required: true, message: '招标方式不能为空', trigger: 'blur' }
          ],
          openMethod: [
            { required: true, message: '开标方式不能为空', trigger: 'blur' }
          ],
          openStep: [
            { required: true, message: '开标步制不能为空', trigger: 'blur' }
          ],
          needApprove: [
            { required: true, message: '是否报名审核不能为空', trigger: 'blur' }
          ],
          approveMethod: [
            { required: true, message: '资格审查方式不能为空', trigger: 'blur' }
          ],
          evaluateMethod: [
            { required: true, message: '评标方式不能为空', trigger: 'blur' }
          ],
          submitMethod: [
            { required: true, message: '评标文件递交方式不能为空', trigger: 'blur' }
          ],
          remark: [
            { required: true, message: '备注不能为空', trigger: 'blur' }
          ],
          createOn: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          createUserId: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          createBy: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          modifiedOn: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          modifiedUserId: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          modifiedBy: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.id = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.id) {
            this.$http({
              url: this.$http.adornUrl(`/bid/project/info/${this.dataForm.id}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.projectCode = data.project.projectCode
                this.dataForm.projectName = data.project.projectName
                this.dataForm.tradeTypeId = data.project.tradeTypeId
                this.dataForm.tradeTypeName = data.project.tradeTypeName
                this.dataForm.projectTypeOneId = data.project.projectTypeOneId
                this.dataForm.projectTypeOneName = data.project.projectTypeOneName
                this.dataForm.projectTypeTwoId = data.project.projectTypeTwoId
                this.dataForm.projectTypeTwoName = data.project.projectTypeTwoName
                this.dataForm.entrustId = data.project.entrustId
                this.dataForm.contractId = data.project.contractId
                this.dataForm.projectManagerId = data.project.projectManagerId
                this.dataForm.projectManager = data.project.projectManager
                this.dataForm.feeServer = data.project.feeServer
                this.dataForm.feeMethod = data.project.feeMethod
                this.dataForm.projectBlock = data.project.projectBlock
                this.dataForm.supervision = data.project.supervision
                this.dataForm.feeSourceId = data.project.feeSourceId
                this.dataForm.feeSource = data.project.feeSource
                this.dataForm.needPurchase = data.project.needPurchase
                this.dataForm.budget = data.project.budget
                this.dataForm.scheduleId = data.project.scheduleId
                this.dataForm.scheduleName = data.project.scheduleName
                this.dataForm.tendereeId = data.project.tendereeId
                this.dataForm.tendereeName = data.project.tendereeName
                this.dataForm.bidScope = data.project.bidScope
                this.dataForm.bidContent = data.project.bidContent
                this.dataForm.province = data.project.province
                this.dataForm.city = data.project.city
                this.dataForm.bidMethod = data.project.bidMethod
                this.dataForm.openMethod = data.project.openMethod
                this.dataForm.openStep = data.project.openStep
                this.dataForm.needApprove = data.project.needApprove
                this.dataForm.approveMethod = data.project.approveMethod
                this.dataForm.evaluateMethod = data.project.evaluateMethod
                this.dataForm.submitMethod = data.project.submitMethod
                this.dataForm.remark = data.project.remark
                this.dataForm.createOn = data.project.createOn
                this.dataForm.createUserId = data.project.createUserId
                this.dataForm.createBy = data.project.createBy
                this.dataForm.modifiedOn = data.project.modifiedOn
                this.dataForm.modifiedUserId = data.project.modifiedUserId
                this.dataForm.modifiedBy = data.project.modifiedBy
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/bid/project/${!this.dataForm.id ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'id': this.dataForm.id || undefined,
                'projectCode': this.dataForm.projectCode,
                'projectName': this.dataForm.projectName,
                'tradeTypeId': this.dataForm.tradeTypeId,
                'tradeTypeName': this.dataForm.tradeTypeName,
                'projectTypeOneId': this.dataForm.projectTypeOneId,
                'projectTypeOneName': this.dataForm.projectTypeOneName,
                'projectTypeTwoId': this.dataForm.projectTypeTwoId,
                'projectTypeTwoName': this.dataForm.projectTypeTwoName,
                'entrustId': this.dataForm.entrustId,
                'contractId': this.dataForm.contractId,
                'projectManagerId': this.dataForm.projectManagerId,
                'projectManager': this.dataForm.projectManager,
                'feeServer': this.dataForm.feeServer,
                'feeMethod': this.dataForm.feeMethod,
                'projectBlock': this.dataForm.projectBlock,
                'supervision': this.dataForm.supervision,
                'feeSourceId': this.dataForm.feeSourceId,
                'feeSource': this.dataForm.feeSource,
                'needPurchase': this.dataForm.needPurchase,
                'budget': this.dataForm.budget,
                'scheduleId': this.dataForm.scheduleId,
                'scheduleName': this.dataForm.scheduleName,
                'tendereeId': this.dataForm.tendereeId,
                'tendereeName': this.dataForm.tendereeName,
                'bidScope': this.dataForm.bidScope,
                'bidContent': this.dataForm.bidContent,
                'province': this.dataForm.province,
                'city': this.dataForm.city,
                'bidMethod': this.dataForm.bidMethod,
                'openMethod': this.dataForm.openMethod,
                'openStep': this.dataForm.openStep,
                'needApprove': this.dataForm.needApprove,
                'approveMethod': this.dataForm.approveMethod,
                'evaluateMethod': this.dataForm.evaluateMethod,
                'submitMethod': this.dataForm.submitMethod,
                'remark': this.dataForm.remark,
                'createOn': this.dataForm.createOn,
                'createUserId': this.dataForm.createUserId,
                'createBy': this.dataForm.createBy,
                'modifiedOn': this.dataForm.modifiedOn,
                'modifiedUserId': this.dataForm.modifiedUserId,
                'modifiedBy': this.dataForm.modifiedBy
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
